import { reactive } from 'vue';

/**
 * 封装 reactive
 *
 * @param {Object} initialState 初始状态
 * @returns {[Object, Function]} [state, updateState]
 */
export function useReactive(initialState) {
  const state = reactive(initialState);

  /**
   * 更新状态
   *
   * @param newState 新状态
   */
  const updateState = (newState) => {
    Object.keys(newState).forEach((key) => {
      state[key] = newState[key];
    });
  };

  return [state, updateState];
}
